package com.cc.controller;

import com.cc.entity.Employees;
import com.cc.entity.R;
import com.cc.enums.HttpEnum;
import com.cc.service.EmployeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/employeeLogin")
@CrossOrigin
public class LoginController {

    @Autowired
    EmployeesService employeesService;

    @RequestMapping("/login")
    public R login(String loginName, String password) {
        Employees employees = employeesService.selectAllByLoginNameAndPassword(loginName, password);
        if (employees != null) {
            return R.success(employees);
        } else {
            return R.fail(HttpEnum.UNAUTHORIZED.getCode(), "用户名或密码错误");
        }
    }
}
